ke.create({
  data:{
    loadTrees:true,
    list:[],
    rule:[],
    form:{},
    isAction:true,

    node:{},

    dialogSelect:{
      status:false
    }
  },
  methods:{
    loadTree:function(){
      this.loadTrees=true
      http.get({
        params:{
          type:1
        },
        success:function(res){
          if(res.code===0){
            vm.$alert(res.msg)
          }else{
            vm.loadTrees=false
            vm.list=[{id:0,name:'管理组',rule_list:[],children:res.data.list}]
            vm.rule=res.data.rule
          }
        }
      })
    },
    // 选项被点击
    onNodeClick:function(item,r){
      this.isAction=false
      this.form=item
      this.node=r
      //authTree
      this.$refs.authTree.setCheckedKeys(this.form.rule_list)
    },
    // 选定
    onSelectOk:function(item){
      this.form.parent_id=item.id
      this.form.ParentName=item.name
      this.dialogSelect.status=false
    },
    // 新增
    onCreate:function(){
      var id=this.form.id
      var name=this.form.name
      var index=this.$treeNodeId
      this.node=this.form
      this.form={}
      this.form.parent_id=id
      this.form.ParentName=name
    },
    // 删除
    onDelete:function(){
      this.$confirm('确定要删除该管理组吗？',{
        callback:function(type){
          if(type=='confirm'){
            http.get({
              url:vm.map.delete,
              params:{
                id:vm.form.id
              },
              success:function(res){
                if(res.code===0){
                  vm.$message.error(res.msg)
                }else{
                  vm.$message.success('删除成功')
                  var parent=vm.node.parent
                  var children=parent.data.children || parent.data
                  var index=children.findIndex(function(d){
                    return d.id === vm.form.id
                  })
                  children.splice(index,1)
                  vm.form={}
      						vm.$refs.authTree.setCheckedKeys([])
                }
              }
            })
          }
        }
      })
    },
    // 保存
    onSubmit:function(){
      var yum=this.node
      this.form.rule_list=this.$refs.authTree.getCheckedKeys()
      ke.submitForm({
        url:this.map.save,
        data:this.form,
        success:function(res){
          if(res.code===0){
            vm.$message.error(res.msg)
          }else{
            vm.$message.success('保存成功')
            var newChild = res.data
            if (!yum.children) {
              vm.$set(yum, 'children', [])
            }
            yum.children.push(newChild)
          }
        }
      })
    }

  },
  created:function(){
    this.loadTree()
  }
})